﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class WaveTemplateDA : IWaveTemplateDA
    {
        private string AUTO_RELEASE = "@AUTO_RELEASE";
        private string CARRIER_EXCLUDES = "@CARRIER_EXCLUDES";
        private string CARRIER_INCLUDES = "@CARRIER_INCLUDES";
        private string CITY_EXCLUDES = "@CITY_EXCLUDES";
        private string CITY_INCLUDES = "@CITY_INCLUDES";
        private string CREATED_BY = "@CREATED_BY";
        private string CUSTOMER_EXCLUDES = "@CUSTOMER_EXCLUDES";
        private string CUSTOMER_INCLUDES = "@CUSTOMER_INCLUDES";
        private string DAYS_AFTER = "@DAYS_AFTER";
        private string DAYS_BEFORE = "@DAYS_BEFORE";
        private string DESCR = "@DESCR";
        private string DRIVER_EXCLUDES = "@DRIVER_EXCLUDES";
        private string DRIVER_INCLUDES = "@DRIVER_INCLUDES";
        private string HOURS_AFTER = "@HOURS_AFTER";
        private string HOURS_BEFORE = "@HOURS_BEFORE";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string MAX_ORDER_LINES = "@MAX_ORDER_LINES";
        private string MAX_ORDERS = "@MAX_ORDERS";
        private string MAX_QTY = "@MAX_QTY";
        private string MAX_SKUS = "@MAX_SKUS";
        private string MAX_VOLUME = "@MAX_VOLUME";
        private string MAX_WEIGHT = "@MAX_WEIGHT";
        private string MIN_ORDER_LINES = "@MIN_ORDER_LINES";
        private string MIN_ORDERS = "@MIN_ORDERS";
        private string MIN_QTY = "@MIN_QTY";
        private string MIN_SKUS = "@MIN_SKUS";
        private string MIN_VOLUME = "@MIN_VOLUME";
        private string MIN_WEIGHT = "@MIN_WEIGHT";
        private string MINUTES_AFTER = "@MINUTES_AFTER";
        private string MINUTES_BEFORE = "@MINUTES_BEFORE";
        private string MULTI_ITEM_WAVE = "@MULTI_ITEM_WAVE";
        private string ORDER_QTY = "@ORDER_QTY";
        private string ORDER_STATUS_EXCLUDES = "@ORDER_STATUS_EXCLUDES";
        private string ORDER_STATUS_INCLUDES = "@ORDER_STATUS_INCLUDES";
        private string ORDER_TYPE_EXCLUDES = "@ORDER_TYPE_EXCLUDES";
        private string ORDER_TYPE_INCLUDES = "@ORDER_TYPE_INCLUDES";
        private string OWNER_EXCLUDES = "@OWNER_EXCLUDES";
        private string OWNER_INCLUDES = "@OWNER_INCLUDES";
        private string PRIORITY = "@PRIORITY";
        private string PROVINCE_EXCLUDES = "@PROVINCE_EXCLUDES";
        private string PROVINCE_INCLUDES = "@PROVINCE_INCLUDES";
        private string ROUTE_EXCLUDES = "@ROUTE_EXCLUDES";
        private string ROUTE_INCLUDES = "@ROUTE_INCLUDES";
        private string RUN_MODE = "@RUN_MODE";
        private string SEC_KILL_WAVE = "@SEC_KILL_WAVE";
        private string SINGLE_ITEM_WAVE = "@SINGLE_ITEM_WAVE";
        private string SKU_CLASS_EXCLUDES = "@SKU_CLASS_EXCLUDES";
        private string SKU_CLASS_INCLUDES = "@SKU_CLASS_INCLUDES";
        private string SKU_EXCLUDES = "@SKU_EXCLUDES";
        private string SKU_INCLUDES = "@SKU_INCLUDES";
        private string SKU_STYLE_EXCLUDES = "@SKU_STYLE_EXCLUDES";
        private string SKU_STYLE_INCLUDES = "@SKU_STYLE_INCLUDES";
        private string SQL_CHECK_WAVE_TEMPLATE_ID_UNIQUE = " SELECT COUNT(1) FROM @_@WAVE_TEMPLATE WHERE WAVE_TEMPLATE_ID = @WAVE_TEMPLATE_ID ";
        private string SQL_DELETE_WAVE_TEMPLATE = " DELETE FROM @_@WAVE_TEMPLATE WHERE WAVE_TEMPLATE_ID = @WAVE_TEMPLATE_ID ";
        private string SQL_INSERT_WAVE_TEMPLATE = " INSERT INTO @_@WAVE_TEMPLATE ( WH_ID, WAVE_TEMPLATE_ID, DESCR, WAVE_FLOW_ID, WAVE_SELECTION, PRIORITY, RUN_MODE, DAYS_BEFORE, DAYS_AFTER, HOURS_BEFORE, MINUTES_BEFORE, HOURS_AFTER, MINUTES_AFTER, OWNER_INCLUDES, OWNER_EXCLUDES, CUSTOMER_INCLUDES, CUSTOMER_EXCLUDES, CARRIER_INCLUDES, CARRIER_EXCLUDES, TRANS_MODE_INCLUDES, TRANS_MODE_EXCLUDES, ROUTE_INCLUDES, ROUTE_EXCLUDES, VEHICLE_INCLUDES, VEHICLE_EXCLUDES, DRIVER_INCLUDES, DRIVER_EXCLUDES, ZONE_INCLUDES, ZONE_EXCLUDES, PROVINCE_INCLUDES, PROVINCE_EXCLUDES, CITY_INCLUDES, CITY_EXCLUDES, ORDER_TYPE_INCLUDES, ORDER_TYPE_EXCLUDES, ORDER_STATUS_INCLUDES, ORDER_STATUS_EXCLUDES, SKU_INCLUDES, SKU_EXCLUDES, SKU_CLASS_INCLUDES, SKU_CLASS_EXCLUDES, SKU_STYLE_INCLUDES, SKU_STYLE_EXCLUDES, MIN_ORDERS, MIN_ORDER_LINES, MIN_SKUS, MIN_QTY, MIN_WEIGHT, MIN_VOLUME, MAX_ORDERS, MAX_ORDER_LINES, MAX_SKUS, MAX_QTY, MAX_WEIGHT, MAX_VOLUME, IS_ACTIVE, AUTO_RELEASE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE,WAVE_GENERATED_BY_OWNER, WAVE_GENERATED_BY_CUSTOMER,WAVE_GENERATED_BY_CARRIER,WAVE_GENERATED_BY_TRANS_MODE,SINGLE_ITEM_WAVE,MULTI_ITEM_WAVE,SEC_KILL_WAVE,ORDER_QTY) VALUES ( @WH_ID, @WAVE_TEMPLATE_ID, @DESCR, @WAVE_FLOW_ID, @WAVE_SELECTION, @PRIORITY, @RUN_MODE, @DAYS_BEFORE, @DAYS_AFTER, @HOURS_BEFORE, @MINUTES_BEFORE, @HOURS_AFTER, @MINUTES_AFTER, @OWNER_INCLUDES, @OWNER_EXCLUDES, @CUSTOMER_INCLUDES, @CUSTOMER_EXCLUDES, @CARRIER_INCLUDES, @CARRIER_EXCLUDES, @TRANS_MODE_INCLUDES, @TRANS_MODE_EXCLUDES, @ROUTE_INCLUDES, @ROUTE_EXCLUDES, @VEHICLE_INCLUDES, @VEHICLE_EXCLUDES, @DRIVER_INCLUDES, @DRIVER_EXCLUDES, @ZONE_INCLUDES, @ZONE_EXCLUDES, @PROVINCE_INCLUDES, @PROVINCE_EXCLUDES, @CITY_INCLUDES, @CITY_EXCLUDES, @ORDER_TYPE_INCLUDES, @ORDER_TYPE_EXCLUDES, @ORDER_STATUS_INCLUDES, @ORDER_STATUS_EXCLUDES, @SKU_INCLUDES, @SKU_EXCLUDES, @SKU_CLASS_INCLUDES, @SKU_CLASS_EXCLUDES, @SKU_STYLE_INCLUDES, @SKU_STYLE_EXCLUDES, @MIN_ORDERS, @MIN_ORDER_LINES, @MIN_SKUS, @MIN_QTY, @MIN_WEIGHT, @MIN_VOLUME, @MAX_ORDERS, @MAX_ORDER_LINES, @MAX_SKUS, @MAX_QTY, @MAX_WEIGHT, @MAX_VOLUME, @IS_ACTIVE, @AUTO_RELEASE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE(),@WAVE_GENERATED_BY_OWNER, @WAVE_GENERATED_BY_CUSTOMER,@WAVE_GENERATED_BY_CARRIER,@WAVE_GENERATED_BY_TRANS_MODE,@SINGLE_ITEM_WAVE,@MULTI_ITEM_WAVE,@SEC_KILL_WAVE,@ORDER_QTY )  ";
        private string SQL_SELECT_ALL_WAVE_TEMPLATE = " SELECT  ROWID, WH_ID, WAVE_TEMPLATE_ID, DESCR, WAVE_FLOW_ID, WAVE_SELECTION, PRIORITY, RUN_MODE, DAYS_BEFORE, DAYS_AFTER, HOURS_BEFORE, MINUTES_BEFORE, HOURS_AFTER, MINUTES_AFTER, OWNER_INCLUDES, OWNER_EXCLUDES, CUSTOMER_INCLUDES, CUSTOMER_EXCLUDES, CARRIER_INCLUDES, CARRIER_EXCLUDES, TRANS_MODE_INCLUDES, TRANS_MODE_EXCLUDES, ROUTE_INCLUDES, ROUTE_EXCLUDES, VEHICLE_INCLUDES, VEHICLE_EXCLUDES, DRIVER_INCLUDES, DRIVER_EXCLUDES, ZONE_INCLUDES, ZONE_EXCLUDES, PROVINCE_INCLUDES, PROVINCE_EXCLUDES, CITY_INCLUDES, CITY_EXCLUDES, ORDER_TYPE_INCLUDES, ORDER_TYPE_EXCLUDES, ORDER_STATUS_INCLUDES, ORDER_STATUS_EXCLUDES, SKU_INCLUDES, SKU_EXCLUDES, SKU_CLASS_INCLUDES, SKU_CLASS_EXCLUDES, SKU_STYLE_INCLUDES, SKU_STYLE_EXCLUDES, MIN_ORDERS, MIN_ORDER_LINES, MIN_SKUS, MIN_QTY, MIN_WEIGHT, MIN_VOLUME, MAX_ORDERS, MAX_ORDER_LINES, MAX_SKUS, MAX_QTY, MAX_WEIGHT, MAX_VOLUME, IS_ACTIVE, AUTO_RELEASE, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE,WAVE_GENERATED_BY_OWNER, WAVE_GENERATED_BY_CUSTOMER,WAVE_GENERATED_BY_CARRIER,WAVE_GENERATED_BY_TRANS_MODE,SINGLE_ITEM_WAVE,MULTI_ITEM_WAVE,SEC_KILL_WAVE,ORDER_QTY  FROM  @_@WAVE_TEMPLATE ";
        private string SQL_UPDATE_WAVE_TEMPLATE = " UPDATE @_@WAVE_TEMPLATE SET WH_ID = @WH_ID, DESCR = @DESCR, WAVE_FLOW_ID = @WAVE_FLOW_ID, WAVE_SELECTION = @WAVE_SELECTION, PRIORITY = @PRIORITY, RUN_MODE = @RUN_MODE, DAYS_BEFORE = @DAYS_BEFORE, DAYS_AFTER = @DAYS_AFTER, HOURS_BEFORE = @HOURS_BEFORE, MINUTES_BEFORE = @MINUTES_BEFORE, HOURS_AFTER = @HOURS_AFTER, MINUTES_AFTER = @MINUTES_AFTER, OWNER_INCLUDES = @OWNER_INCLUDES, OWNER_EXCLUDES = @OWNER_EXCLUDES, CUSTOMER_INCLUDES = @CUSTOMER_INCLUDES, CUSTOMER_EXCLUDES = @CUSTOMER_EXCLUDES, CARRIER_INCLUDES = @CARRIER_INCLUDES, CARRIER_EXCLUDES = @CARRIER_EXCLUDES, TRANS_MODE_INCLUDES = @TRANS_MODE_INCLUDES, TRANS_MODE_EXCLUDES = @TRANS_MODE_EXCLUDES, ROUTE_INCLUDES = @ROUTE_INCLUDES, ROUTE_EXCLUDES = @ROUTE_EXCLUDES, VEHICLE_INCLUDES = @VEHICLE_INCLUDES, VEHICLE_EXCLUDES = @VEHICLE_EXCLUDES, DRIVER_INCLUDES = @DRIVER_INCLUDES, DRIVER_EXCLUDES = @DRIVER_EXCLUDES, ZONE_INCLUDES = @ZONE_INCLUDES, ZONE_EXCLUDES = @ZONE_EXCLUDES, PROVINCE_INCLUDES = @PROVINCE_INCLUDES, PROVINCE_EXCLUDES = @PROVINCE_EXCLUDES, CITY_INCLUDES = @CITY_INCLUDES, CITY_EXCLUDES = @CITY_EXCLUDES, ORDER_TYPE_INCLUDES = @ORDER_TYPE_INCLUDES, ORDER_TYPE_EXCLUDES = @ORDER_TYPE_EXCLUDES, ORDER_STATUS_INCLUDES = @ORDER_STATUS_INCLUDES, ORDER_STATUS_EXCLUDES = @ORDER_STATUS_EXCLUDES, SKU_INCLUDES = @SKU_INCLUDES, SKU_EXCLUDES = @SKU_EXCLUDES, SKU_CLASS_INCLUDES = @SKU_CLASS_INCLUDES, SKU_CLASS_EXCLUDES = @SKU_CLASS_EXCLUDES, SKU_STYLE_INCLUDES = @SKU_STYLE_INCLUDES, SKU_STYLE_EXCLUDES = @SKU_STYLE_EXCLUDES, MIN_ORDERS = @MIN_ORDERS, MIN_ORDER_LINES = @MIN_ORDER_LINES, MIN_SKUS = @MIN_SKUS, MIN_QTY = @MIN_QTY, MIN_WEIGHT = @MIN_WEIGHT, MIN_VOLUME = @MIN_VOLUME, MAX_ORDERS = @MAX_ORDERS, MAX_ORDER_LINES = @MAX_ORDER_LINES, MAX_SKUS = @MAX_SKUS, MAX_QTY = @MAX_QTY, MAX_WEIGHT = @MAX_WEIGHT, MAX_VOLUME = @MAX_VOLUME, IS_ACTIVE = @IS_ACTIVE, AUTO_RELEASE = @AUTO_RELEASE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE(), WAVE_GENERATED_BY_OWNER=@WAVE_GENERATED_BY_OWNER, WAVE_GENERATED_BY_CUSTOMER=@WAVE_GENERATED_BY_CUSTOMER,WAVE_GENERATED_BY_CARRIER=@WAVE_GENERATED_BY_CARRIER,WAVE_GENERATED_BY_TRANS_MODE=@WAVE_GENERATED_BY_TRANS_MODE,SINGLE_ITEM_WAVE=@SINGLE_ITEM_WAVE,MULTI_ITEM_WAVE=@MULTI_ITEM_WAVE,SEC_KILL_WAVE=@SEC_KILL_WAVE,ORDER_QTY=@ORDER_QTY WHERE WAVE_TEMPLATE_ID = @WAVE_TEMPLATE_ID  ";
        private string TRANS_MODE_EXCLUDES = "@TRANS_MODE_EXCLUDES";
        private string TRANS_MODE_INCLUDES = "@TRANS_MODE_INCLUDES";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string VEHICLE_EXCLUDES = "@VEHICLE_EXCLUDES";
        private string VEHICLE_INCLUDES = "@VEHICLE_INCLUDES";
        private string WAVE_FLOW_ID = "@WAVE_FLOW_ID";
        private string WAVE_GENERATED_BY_CARRIER = "@WAVE_GENERATED_BY_CARRIER";
        private string WAVE_GENERATED_BY_CUSTOMER = "@WAVE_GENERATED_BY_CUSTOMER";
        private string WAVE_GENERATED_BY_OWNER = "@WAVE_GENERATED_BY_OWNER";
        private string WAVE_GENERATED_BY_TRANS_MODE = "@WAVE_GENERATED_BY_TRANS_MODE";
        private string WAVE_SELECTION = "@WAVE_SELECTION";
        private string WAVE_TEMPLATE_ID = "@WAVE_TEMPLATE_ID";
        private string WH_ID = "@WH_ID";
        private string ZONE_EXCLUDES = "@ZONE_EXCLUDES";
        private string ZONE_INCLUDES = "@ZONE_INCLUDES";

        public bool CheckWaveTemplateIDUnique(string waveTemplateID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", waveTemplateID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_WAVE_TEMPLATE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckWaveTemplateIDUnique(DataBase dataBase, DbTransaction tran, string waveTemplateID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", waveTemplateID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_WAVE_TEMPLATE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteWaveTemplate(List<string> waveTemplateID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int j = 0; j < waveTemplateID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", waveTemplateID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteWaveTemplate(DataBase dataBase, DbTransaction tran, List<string> waveTemplateID, string whLoginID)
        {
            int result = 0;
            try
            {
                for (int j = 0; j < waveTemplateID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", waveTemplateID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllWaveTemplate(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllWaveTemplate(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public WaveTemplateInfo GetWaveTemplateByID(string wavetemplateID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID) + " WHERE WAVE_TEMPLATE_ID = @WAVE_TEMPLATE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", wavetemplateID) };
            WaveTemplateInfo waveTemplateInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    waveTemplateInfo = new WaveTemplateInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["WAVE_TEMPLATE_ID"].ToString(), reader["DESCR"].ToString(), reader["WAVE_FLOW_ID"].ToString(), reader["WAVE_SELECTION"].ToString(), reader["PRIORITY"].ToString(), reader["RUN_MODE"].ToString(), (reader["DAYS_BEFORE"].ToString() != "") ? int.Parse(reader["DAYS_BEFORE"].ToString()) : 0, (reader["DAYS_AFTER"].ToString() != "") ? int.Parse(reader["DAYS_AFTER"].ToString()) : 0, (reader["HOURS_BEFORE"].ToString() != "") ? int.Parse(reader["HOURS_BEFORE"].ToString()) : 0, (reader["MINUTES_BEFORE"].ToString() != "") ? int.Parse(reader["MINUTES_BEFORE"].ToString()) : 0, (reader["HOURS_AFTER"].ToString() != "") ? int.Parse(reader["HOURS_AFTER"].ToString()) : 0, (reader["MINUTES_AFTER"].ToString() != "") ? int.Parse(reader["MINUTES_AFTER"].ToString()) : 0, reader["OWNER_INCLUDES"].ToString(), reader["OWNER_EXCLUDES"].ToString(), reader["CUSTOMER_INCLUDES"].ToString(), reader["CUSTOMER_EXCLUDES"].ToString(), reader["CARRIER_INCLUDES"].ToString(), reader["CARRIER_EXCLUDES"].ToString(), reader["TRANS_MODE_INCLUDES"].ToString(), reader["TRANS_MODE_EXCLUDES"].ToString(), reader["ROUTE_INCLUDES"].ToString(), reader["ROUTE_EXCLUDES"].ToString(), reader["VEHICLE_INCLUDES"].ToString(), reader["VEHICLE_EXCLUDES"].ToString(), reader["DRIVER_INCLUDES"].ToString(), reader["DRIVER_EXCLUDES"].ToString(), reader["ZONE_INCLUDES"].ToString(), reader["ZONE_EXCLUDES"].ToString(), reader["PROVINCE_INCLUDES"].ToString(), reader["PROVINCE_EXCLUDES"].ToString(), reader["CITY_INCLUDES"].ToString(), reader["CITY_EXCLUDES"].ToString(), reader["ORDER_TYPE_INCLUDES"].ToString(), reader["ORDER_TYPE_EXCLUDES"].ToString(), reader["ORDER_STATUS_INCLUDES"].ToString(), reader["ORDER_STATUS_EXCLUDES"].ToString(), reader["SKU_INCLUDES"].ToString(), reader["SKU_EXCLUDES"].ToString(), reader["SKU_CLASS_INCLUDES"].ToString(), reader["SKU_CLASS_EXCLUDES"].ToString(), reader["SKU_STYLE_INCLUDES"].ToString(), reader["SKU_STYLE_EXCLUDES"].ToString(), (reader["MIN_ORDERS"].ToString() != "") ? int.Parse(reader["MIN_ORDERS"].ToString()) : 0, (reader["MIN_ORDER_LINES"].ToString() != "") ? int.Parse(reader["MIN_ORDER_LINES"].ToString()) : 0, (reader["MIN_SKUS"].ToString() != "") ? int.Parse(reader["MIN_SKUS"].ToString()) : 0, (reader["MIN_QTY"].ToString() != "") ? int.Parse(reader["MIN_QTY"].ToString()) : 0, (reader["MIN_WEIGHT"].ToString() != "") ? int.Parse(reader["MIN_WEIGHT"].ToString()) : 0, (reader["MIN_VOLUME"].ToString() != "") ? int.Parse(reader["MIN_VOLUME"].ToString()) : 0, (reader["MAX_ORDERS"].ToString() != "") ? int.Parse(reader["MAX_ORDERS"].ToString()) : 0, (reader["MAX_ORDER_LINES"].ToString() != "") ? int.Parse(reader["MAX_ORDER_LINES"].ToString()) : 0, (reader["MAX_SKUS"].ToString() != "") ? int.Parse(reader["MAX_SKUS"].ToString()) : 0, (reader["MAX_QTY"].ToString() != "") ? int.Parse(reader["MAX_QTY"].ToString()) : 0, (reader["MAX_WEIGHT"].ToString() != "") ? int.Parse(reader["MAX_WEIGHT"].ToString()) : 0, (reader["MAX_VOLUME"].ToString() != "") ? int.Parse(reader["MAX_VOLUME"].ToString()) : 0, reader["IS_ACTIVE"].ToString(), reader["AUTO_RELEASE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["WAVE_GENERATED_BY_OWNER"].ToString(), reader["WAVE_GENERATED_BY_CUSTOMER"].ToString(), reader["WAVE_GENERATED_BY_CARRIER"].ToString(), reader["WAVE_GENERATED_BY_TRANS_MODE"].ToString(), reader["SINGLE_ITEM_WAVE"].ToString(), reader["MULTI_ITEM_WAVE"].ToString(), reader["SEC_KILL_WAVE"].ToString(), (reader["ORDER_QTY"].ToString() != "") ? int.Parse(reader["ORDER_QTY"].ToString()) : 0);
                }
            }
            return waveTemplateInfo;
        }

        public WaveTemplateInfo GetWaveTemplateByID(DataBase dataBase, DbTransaction tran, string wavetemplateID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID) + " WHERE WAVE_TEMPLATE_ID = @WAVE_TEMPLATE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_TEMPLATE_ID", wavetemplateID) };
            WaveTemplateInfo waveTemplateInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                waveTemplateInfo = new WaveTemplateInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["WAVE_TEMPLATE_ID"].ToString(), reader["DESCR"].ToString(), reader["WAVE_FLOW_ID"].ToString(), reader["WAVE_SELECTION"].ToString(), reader["PRIORITY"].ToString(), reader["RUN_MODE"].ToString(), (reader["DAYS_BEFORE"].ToString() != "") ? int.Parse(reader["DAYS_BEFORE"].ToString()) : 0, (reader["DAYS_AFTER"].ToString() != "") ? int.Parse(reader["DAYS_AFTER"].ToString()) : 0, (reader["HOURS_BEFORE"].ToString() != "") ? int.Parse(reader["HOURS_BEFORE"].ToString()) : 0, (reader["MINUTES_BEFORE"].ToString() != "") ? int.Parse(reader["MINUTES_BEFORE"].ToString()) : 0, (reader["HOURS_AFTER"].ToString() != "") ? int.Parse(reader["HOURS_AFTER"].ToString()) : 0, (reader["MINUTES_AFTER"].ToString() != "") ? int.Parse(reader["MINUTES_AFTER"].ToString()) : 0, reader["OWNER_INCLUDES"].ToString(), reader["OWNER_EXCLUDES"].ToString(), reader["CUSTOMER_INCLUDES"].ToString(), reader["CUSTOMER_EXCLUDES"].ToString(), reader["CARRIER_INCLUDES"].ToString(), reader["CARRIER_EXCLUDES"].ToString(), reader["TRANS_MODE_INCLUDES"].ToString(), reader["TRANS_MODE_EXCLUDES"].ToString(), reader["ROUTE_INCLUDES"].ToString(), reader["ROUTE_EXCLUDES"].ToString(), reader["VEHICLE_INCLUDES"].ToString(), reader["VEHICLE_EXCLUDES"].ToString(), reader["DRIVER_INCLUDES"].ToString(), reader["DRIVER_EXCLUDES"].ToString(), reader["ZONE_INCLUDES"].ToString(), reader["ZONE_EXCLUDES"].ToString(), reader["PROVINCE_INCLUDES"].ToString(), reader["PROVINCE_EXCLUDES"].ToString(), reader["CITY_INCLUDES"].ToString(), reader["CITY_EXCLUDES"].ToString(), reader["ORDER_TYPE_INCLUDES"].ToString(), reader["ORDER_TYPE_EXCLUDES"].ToString(), reader["ORDER_STATUS_INCLUDES"].ToString(), reader["ORDER_STATUS_EXCLUDES"].ToString(), reader["SKU_INCLUDES"].ToString(), reader["SKU_EXCLUDES"].ToString(), reader["SKU_CLASS_INCLUDES"].ToString(), reader["SKU_CLASS_EXCLUDES"].ToString(), reader["SKU_STYLE_INCLUDES"].ToString(), reader["SKU_STYLE_EXCLUDES"].ToString(), (reader["MIN_ORDERS"].ToString() != "") ? int.Parse(reader["MIN_ORDERS"].ToString()) : 0, (reader["MIN_ORDER_LINES"].ToString() != "") ? int.Parse(reader["MIN_ORDER_LINES"].ToString()) : 0, (reader["MIN_SKUS"].ToString() != "") ? int.Parse(reader["MIN_SKUS"].ToString()) : 0, (reader["MIN_QTY"].ToString() != "") ? int.Parse(reader["MIN_QTY"].ToString()) : 0, (reader["MIN_WEIGHT"].ToString() != "") ? int.Parse(reader["MIN_WEIGHT"].ToString()) : 0, (reader["MIN_VOLUME"].ToString() != "") ? int.Parse(reader["MIN_VOLUME"].ToString()) : 0, (reader["MAX_ORDERS"].ToString() != "") ? int.Parse(reader["MAX_ORDERS"].ToString()) : 0, (reader["MAX_ORDER_LINES"].ToString() != "") ? int.Parse(reader["MAX_ORDER_LINES"].ToString()) : 0, (reader["MAX_SKUS"].ToString() != "") ? int.Parse(reader["MAX_SKUS"].ToString()) : 0, (reader["MAX_QTY"].ToString() != "") ? int.Parse(reader["MAX_QTY"].ToString()) : 0, (reader["MAX_WEIGHT"].ToString() != "") ? int.Parse(reader["MAX_WEIGHT"].ToString()) : 0, (reader["MAX_VOLUME"].ToString() != "") ? int.Parse(reader["MAX_VOLUME"].ToString()) : 0, reader["IS_ACTIVE"].ToString(), reader["AUTO_RELEASE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["WAVE_GENERATED_BY_OWNER"].ToString(), reader["WAVE_GENERATED_BY_CUSTOMER"].ToString(), reader["WAVE_GENERATED_BY_CARRIER"].ToString(), reader["WAVE_GENERATED_BY_TRANS_MODE"].ToString(), reader["SINGLE_ITEM_WAVE"].ToString(), reader["MULTI_ITEM_WAVE"].ToString(), reader["SEC_KILL_WAVE"].ToString(), (reader["ORDER_QTY"].ToString() != "") ? int.Parse(reader["ORDER_QTY"].ToString()) : 0);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return waveTemplateInfo;
        }

        public DataSet GetWaveTemplateByQueryList(List<string> sqlWhere, WaveTemplateQueryEntity wavetemplateQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!wavetemplateQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, wavetemplateQuery.CurrentPage, wavetemplateQuery.PageSize, wavetemplateQuery.SortField, wavetemplateQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetWaveTemplateByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, WaveTemplateQueryEntity wavetemplateQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_WAVE_TEMPLATE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            temp = PagingHelper.GetPagingSQL(temp, wavetemplateQuery.CurrentPage, wavetemplateQuery.PageSize, wavetemplateQuery.SortField, wavetemplateQuery.SortDirection);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertWaveTemplate(WaveTemplateInfo waveTemplateInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                waveTemplateInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_WaveTemplate_Parameters(waveTemplateInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertWaveTemplate(DataBase dataBase, DbTransaction tran, WaveTemplateInfo waveTemplateInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                waveTemplateInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_WaveTemplate_Parameters(waveTemplateInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_WaveTemplate_Parameters(WaveTemplateInfo waveTemplateInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.WAVE_TEMPLATE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DESCR, SqlDbType.VarChar, 100), new SqlParameter(this.WAVE_FLOW_ID, SqlDbType.VarChar, 20), new SqlParameter(this.WAVE_SELECTION, SqlDbType.VarChar, 20), new SqlParameter(this.PRIORITY, SqlDbType.VarChar, 20), new SqlParameter(this.RUN_MODE, SqlDbType.VarChar, 20), new SqlParameter(this.DAYS_BEFORE, SqlDbType.Int, 4), new SqlParameter(this.DAYS_AFTER, SqlDbType.Int, 4), new SqlParameter(this.HOURS_BEFORE, SqlDbType.Int, 4), new SqlParameter(this.MINUTES_BEFORE, SqlDbType.Int, 4), new SqlParameter(this.HOURS_AFTER, SqlDbType.Int, 4), new SqlParameter(this.MINUTES_AFTER, SqlDbType.Int, 4), new SqlParameter(this.OWNER_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.OWNER_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.CUSTOMER_INCLUDES, SqlDbType.VarChar, 0x80), 
                new SqlParameter(this.CUSTOMER_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.CARRIER_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.CARRIER_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.TRANS_MODE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.TRANS_MODE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ROUTE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ROUTE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.VEHICLE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.VEHICLE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.DRIVER_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.DRIVER_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ZONE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ZONE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.PROVINCE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.PROVINCE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.CITY_INCLUDES, SqlDbType.VarChar, 0x80), 
                new SqlParameter(this.CITY_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ORDER_TYPE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ORDER_TYPE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ORDER_STATUS_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.ORDER_STATUS_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_CLASS_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_CLASS_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_STYLE_INCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.SKU_STYLE_EXCLUDES, SqlDbType.VarChar, 0x80), new SqlParameter(this.MIN_ORDERS, SqlDbType.Int, 4), new SqlParameter(this.MIN_ORDER_LINES, SqlDbType.Int, 4), new SqlParameter(this.MIN_SKUS, SqlDbType.Int, 4), new SqlParameter(this.MIN_QTY, SqlDbType.Int, 4), new SqlParameter(this.MIN_WEIGHT, SqlDbType.Int, 4), 
                new SqlParameter(this.MIN_VOLUME, SqlDbType.Int, 4), new SqlParameter(this.MAX_ORDERS, SqlDbType.Int, 4), new SqlParameter(this.MAX_ORDER_LINES, SqlDbType.Int, 4), new SqlParameter(this.MAX_SKUS, SqlDbType.Int, 4), new SqlParameter(this.MAX_QTY, SqlDbType.Int, 4), new SqlParameter(this.MAX_WEIGHT, SqlDbType.Int, 4), new SqlParameter(this.MAX_VOLUME, SqlDbType.Int, 4), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.AUTO_RELEASE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.WAVE_GENERATED_BY_OWNER, SqlDbType.VarChar, 1), new SqlParameter(this.WAVE_GENERATED_BY_CUSTOMER, SqlDbType.VarChar, 1), new SqlParameter(this.WAVE_GENERATED_BY_CARRIER, SqlDbType.VarChar, 1), new SqlParameter(this.WAVE_GENERATED_BY_TRANS_MODE, SqlDbType.VarChar, 1), new SqlParameter(this.SINGLE_ITEM_WAVE, SqlDbType.VarChar, 1), 
                new SqlParameter(this.MULTI_ITEM_WAVE, SqlDbType.VarChar, 1), new SqlParameter(this.SEC_KILL_WAVE, SqlDbType.VarChar, 1), new SqlParameter(this.ORDER_QTY, SqlDbType.Int)
             };
            if (!string.IsNullOrEmpty(waveTemplateInfo.WhID))
            {
                paramArray[0].Value = waveTemplateInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = waveTemplateInfo.WaveTemplateID;
            paramArray[2].Value = waveTemplateInfo.Descr;
            paramArray[3].Value = waveTemplateInfo.WaveFlowID;
            if (!string.IsNullOrEmpty(waveTemplateInfo.WaveSelection))
            {
                paramArray[4].Value = waveTemplateInfo.WaveSelection;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            paramArray[5].Value = waveTemplateInfo.Priority;
            paramArray[6].Value = waveTemplateInfo.RunMode;
            paramArray[7].Value = waveTemplateInfo.DaysBefore;
            paramArray[8].Value = waveTemplateInfo.DaysAfter;
            paramArray[9].Value = waveTemplateInfo.HoursBefore;
            paramArray[10].Value = waveTemplateInfo.MinutesBefore;
            paramArray[11].Value = waveTemplateInfo.HoursAfter;
            paramArray[12].Value = waveTemplateInfo.MinutesAfter;
            if (!string.IsNullOrEmpty(waveTemplateInfo.OwnerIncludes))
            {
                paramArray[13].Value = waveTemplateInfo.OwnerIncludes;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.OwnerExcludes))
            {
                paramArray[14].Value = waveTemplateInfo.OwnerExcludes;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CustomerIncludes))
            {
                paramArray[15].Value = waveTemplateInfo.CustomerIncludes;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CustomerExcludes))
            {
                paramArray[0x10].Value = waveTemplateInfo.CustomerExcludes;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CarrierIncludes))
            {
                paramArray[0x11].Value = waveTemplateInfo.CarrierIncludes;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CarrierExcludes))
            {
                paramArray[0x12].Value = waveTemplateInfo.CarrierExcludes;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.TransModeIncludes))
            {
                paramArray[0x13].Value = waveTemplateInfo.TransModeIncludes;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.TransModeExcludes))
            {
                paramArray[20].Value = waveTemplateInfo.TransModeExcludes;
            }
            else
            {
                paramArray[20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.RouteIncludes))
            {
                paramArray[0x15].Value = waveTemplateInfo.RouteIncludes;
            }
            else
            {
                paramArray[0x15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.RouteExcludes))
            {
                paramArray[0x16].Value = waveTemplateInfo.RouteExcludes;
            }
            else
            {
                paramArray[0x16].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.VehicleIncludes))
            {
                paramArray[0x17].Value = waveTemplateInfo.VehicleIncludes;
            }
            else
            {
                paramArray[0x17].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.VehicleExcludes))
            {
                paramArray[0x18].Value = waveTemplateInfo.VehicleExcludes;
            }
            else
            {
                paramArray[0x18].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.DriverIncludes))
            {
                paramArray[0x19].Value = waveTemplateInfo.DriverIncludes;
            }
            else
            {
                paramArray[0x19].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.DriverExcludes))
            {
                paramArray[0x1a].Value = waveTemplateInfo.DriverExcludes;
            }
            else
            {
                paramArray[0x1a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.ZoneIncludes))
            {
                paramArray[0x1b].Value = waveTemplateInfo.ZoneIncludes;
            }
            else
            {
                paramArray[0x1b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.ZoneExcludes))
            {
                paramArray[0x1c].Value = waveTemplateInfo.ZoneExcludes;
            }
            else
            {
                paramArray[0x1c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.ProvinceIncludes))
            {
                paramArray[0x1d].Value = waveTemplateInfo.ProvinceIncludes;
            }
            else
            {
                paramArray[0x1d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.ProvinceExcludes))
            {
                paramArray[30].Value = waveTemplateInfo.ProvinceExcludes;
            }
            else
            {
                paramArray[30].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CityIncludes))
            {
                paramArray[0x1f].Value = waveTemplateInfo.CityIncludes;
            }
            else
            {
                paramArray[0x1f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.CityExcludes))
            {
                paramArray[0x20].Value = waveTemplateInfo.CityExcludes;
            }
            else
            {
                paramArray[0x20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.OrderTypeIncludes))
            {
                paramArray[0x21].Value = waveTemplateInfo.OrderTypeIncludes;
            }
            else
            {
                paramArray[0x21].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.OrderTypeExcludes))
            {
                paramArray[0x22].Value = waveTemplateInfo.OrderTypeExcludes;
            }
            else
            {
                paramArray[0x22].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.OrderStatusIncludes))
            {
                paramArray[0x23].Value = waveTemplateInfo.OrderStatusIncludes;
            }
            else
            {
                paramArray[0x23].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.OrderStatusExcludes))
            {
                paramArray[0x24].Value = waveTemplateInfo.OrderStatusExcludes;
            }
            else
            {
                paramArray[0x24].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuIncludes))
            {
                paramArray[0x25].Value = waveTemplateInfo.SkuIncludes;
            }
            else
            {
                paramArray[0x25].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuExcludes))
            {
                paramArray[0x26].Value = waveTemplateInfo.SkuExcludes;
            }
            else
            {
                paramArray[0x26].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuClassIncludes))
            {
                paramArray[0x27].Value = waveTemplateInfo.SkuClassIncludes;
            }
            else
            {
                paramArray[0x27].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuClassExcludes))
            {
                paramArray[40].Value = waveTemplateInfo.SkuClassExcludes;
            }
            else
            {
                paramArray[40].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuStyleIncludes))
            {
                paramArray[0x29].Value = waveTemplateInfo.SkuStyleIncludes;
            }
            else
            {
                paramArray[0x29].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SkuStyleExcludes))
            {
                paramArray[0x2a].Value = waveTemplateInfo.SkuStyleExcludes;
            }
            else
            {
                paramArray[0x2a].Value = DBNull.Value;
            }
            paramArray[0x2b].Value = waveTemplateInfo.MinOrders;
            paramArray[0x2c].Value = waveTemplateInfo.MinOrderLines;
            paramArray[0x2d].Value = waveTemplateInfo.MinSkus;
            paramArray[0x2e].Value = waveTemplateInfo.MinQty;
            paramArray[0x2f].Value = waveTemplateInfo.MinWeight;
            paramArray[0x30].Value = waveTemplateInfo.MinVolume;
            paramArray[0x31].Value = waveTemplateInfo.MaxOrders;
            paramArray[50].Value = waveTemplateInfo.MaxOrderLines;
            paramArray[0x33].Value = waveTemplateInfo.MaxSkus;
            paramArray[0x34].Value = waveTemplateInfo.MaxQty;
            paramArray[0x35].Value = waveTemplateInfo.MaxWeight;
            paramArray[0x36].Value = waveTemplateInfo.MaxVolume;
            paramArray[0x37].Value = waveTemplateInfo.IsActive;
            paramArray[0x38].Value = waveTemplateInfo.AutoRelease;
            paramArray[0x39].Value = waveTemplateInfo.CreatedBy;
            paramArray[0x3a].Value = waveTemplateInfo.UpdatedBy;
            if (!string.IsNullOrEmpty(waveTemplateInfo.WaveGeneratedByOwner))
            {
                paramArray[0x3b].Value = waveTemplateInfo.WaveGeneratedByOwner;
            }
            else
            {
                paramArray[0x3b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.WaveGeneratedByCustomer))
            {
                paramArray[60].Value = waveTemplateInfo.WaveGeneratedByCustomer;
            }
            else
            {
                paramArray[60].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.WaveGeneratedByCarrier))
            {
                paramArray[0x3d].Value = waveTemplateInfo.WaveGeneratedByCarrier;
            }
            else
            {
                paramArray[0x3d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.WaveGeneratedByTransMode))
            {
                paramArray[0x3e].Value = waveTemplateInfo.WaveGeneratedByTransMode;
            }
            else
            {
                paramArray[0x3e].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SingleItemWave))
            {
                paramArray[0x3f].Value = waveTemplateInfo.SingleItemWave;
            }
            else
            {
                paramArray[0x3f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.MultiItemWave))
            {
                paramArray[0x40].Value = waveTemplateInfo.MultiItemWave;
            }
            else
            {
                paramArray[0x40].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(waveTemplateInfo.SecKillWave))
            {
                paramArray[0x41].Value = waveTemplateInfo.SecKillWave;
            }
            else
            {
                paramArray[0x41].Value = DBNull.Value;
            }
            paramArray[0x42].Value = waveTemplateInfo.OrderQty;
            return paramArray;
        }

        public int UpdateWaveTemplate(WaveTemplateInfo waveTemplateInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                waveTemplateInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_WaveTemplate_Parameters(waveTemplateInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateWaveTemplate(DataBase dataBase, DbTransaction tran, WaveTemplateInfo waveTemplateInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                waveTemplateInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_WaveTemplate_Parameters(waveTemplateInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_WAVE_TEMPLATE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

